<template>
    <div id="dialog-container">
        <el-dialog v-dialogDrag 
            title="编辑账号信息" append-to-body
            :visible.sync="dialogVisible" @close="$emit('update:show', false)" :before-close="handleClose" :show="show"
            :close-on-click-modal="false" width="680px">
            <el-form :model="form" :rules="rules" ref="form" :inline="true" size="small" label-width="100px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="工号：" prop="name">
                            <el-input v-model="form.name"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="用户姓名：" prop="userName">
                            <el-input v-model="form.userName"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="密码：" prop="password">
                            <el-input v-model="form.password"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="厂：">
                            <el-input v-model="form.a"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="确认密码：">
                            <el-input v-model="form.a"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="职务：">
                            <el-input v-model="form.a"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="部门：">
                            <el-input v-model="form.a"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="科室：">
                            <el-input v-model="form.a"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="邮件地址：" prop="email">
                            <el-input v-model="form.email"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="备注：" prop="remark">
                            <el-input v-model="form.remark" type="textarea" :row="2" style="width: 520px;"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm('form')">确 定</el-button>
                <el-button @click="dialogVisible = false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import { changeFormitemSpace } from 'utils/common'     // 表单验证有误时，改变表单的上下间距
    import { setUserOperateService } from 'service/system-manage/user-manage'
    export default {
        data() {
            return {
                dialogVisible: this.show,
                form: {
                    name: '',
                    userName: '',
                    password: '',
                    email: '',
                    remark: '',
                    a: ''
                },
                rules: {
                    name: [
                        { required: true, message: '请输入工号', trigger: 'blur' }
                    ],
                    userName: [
                        { required: true, message: '请输入用户姓名', trigger: 'blur' }
                    ]
                }
            }
        },
        props: {
            show: {
                type: Boolean,
                default: false
            }
        },
        watch: {
            show() {
                this.dialogVisible = this.show;
            }
        },
        methods: {
            handleClose() {
                this.dialogVisible = false;
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // let data = {"cmd":"userOpt",
                        //     "token":"123123",
                        //     "userId": "13",
                        //     "name": "",
                        //     "password": "123",
                        //     "userName": "hhhhh",
                        //     "mobile": "",
                        //     "email": "",
                        //     "remark": "",
                        //     "type":"2"
                        //    };
                        // let params = {"userId": "", "name": this.form.name, "password": this.form.password, "userName": this.form.userName, "mobile": this.form.mobile, "email": this.form.email, "remark": this.form.remark, "type": "1"};
                        // setUserOperateService(params)
                        //     .then((res) => {
                        //         console.log(res)
                        //         // this.$emit('updateTable', true);   // 将选择的账户信息传递到父页面
                        //     });
                        this.dialogVisible = false;
                    } else {
                        changeFormitemSpace(document);
                        console.log('error submit!!');
                        return false;
                    }
                    
                });
            }
        }
    }
</script>

